using System;
using System.Collections.Generic;
using System.Reflection;
namespace AppToolKit.Business.Denote
{
	[Serializable]
	public abstract class DenotationTempalte<T> : IEquatable<DenotationTempalte<T>>
	{
		public T Value
		{
			get;
			set;
		}
		public override bool Equals(object obj)
		{
			return !object.ReferenceEquals(null, obj) && (object.ReferenceEquals(this, obj) || (obj.GetType() == typeof(DenotationTempalte<T>) && this.Equals((DenotationTempalte<T>)obj)));
		}
		public bool Equals(DenotationTempalte<T> obj)
		{
			return !object.ReferenceEquals(null, obj) && (object.ReferenceEquals(this, obj) || object.Equals(obj.Value, this.Value));
		}
		public override int GetHashCode()
		{
			int arg_25_0;
			if (this.Value == null)
			{
				arg_25_0 = 0;
			}
			else
			{
				T value = this.Value;
				arg_25_0 = value.GetHashCode();
			}
			return arg_25_0;
		}
		public static bool operator ==(DenotationTempalte<T> left, DenotationTempalte<T> right)
		{
			return object.Equals(left, right);
		}
		public static implicit operator T(DenotationTempalte<T> right)
		{
			return right.Value;
		}
		public static bool operator !=(DenotationTempalte<T> left, DenotationTempalte<T> right)
		{
			return !object.Equals(left, right);
		}
		protected DenotationTempalte()
		{
		}
		protected DenotationTempalte(T value)
		{
			if (value != null)
			{
				this.Value = value;
			}
		}
		public override string ToString()
		{
			T value = this.Value;
			return value.ToString();
		}
		public static TDenotationDerive GetDenotation<TDenotationDerive>(T a) where TDenotationDerive : DenotationTempalte<T>
		{
			Type typeFromHandle = typeof(TDenotationDerive);
			List<TDenotationDerive> allField = DenotationTempalte<T>.GetAllField<TDenotationDerive>(typeFromHandle);
			foreach (TDenotationDerive current in allField)
			{
				T value = current.Value;
				if (value.Equals(a))
				{
					return current;
				}
			}
			throw new DenotationExecption("Not Found");
		}
		public static List<TDenotationDerive> GetAllDenotation<TDenotationDerive>() where TDenotationDerive : DenotationTempalte<T>
		{
			Type typeFromHandle = typeof(T);
			return DenotationTempalte<T>.GetAllField<TDenotationDerive>(typeFromHandle);
		}
		public static List<TDenotationDerive> GetAllDenotation<TDenotationDerive>(Type t) where TDenotationDerive : DenotationTempalte<T>
		{
			return DenotationTempalte<T>.GetAllField<TDenotationDerive>(t);
		}
		public static List<TDenotationDerive> GetAllField<TDenotationDerive>(Type t) where TDenotationDerive : DenotationTempalte<T>
		{
			List<TDenotationDerive> list = new List<TDenotationDerive>();
			FieldInfo[] fields = t.GetFields(BindingFlags.Static | BindingFlags.Public);
			FieldInfo[] array = fields;
			for (int i = 0; i < array.Length; i++)
			{
				FieldInfo fieldInfo = array[i];
				if (fieldInfo.FieldType.Equals(typeof(TDenotationDerive)) || fieldInfo.FieldType.IsSubclassOf(typeof(TDenotationDerive)))
				{
					list.Add((TDenotationDerive)fieldInfo.GetValue(null));
				}
			}
			return list;
		}
	}
}
